package com.my.chapter21;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class practice3 {
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        for(int i = 0; i < 5; i++)
            exec.execute(new Printer());
        Thread.yield();
        exec.shutdown();
        exec = Executors.newFixedThreadPool(5);
        for(int i = 0; i < 5; i++)
            exec.execute(new Printer());
        Thread.yield();
        exec.shutdown();
        exec = Executors.newSingleThreadExecutor();
        for(int i = 0; i < 5; i++)
            exec.execute(new Printer());
        Thread.yield();
        exec.shutdown();
    }
}

/*对shutdown（）的调用是一个异步方法调用，用于启动有序的关闭过程。
JDK声明：“关闭后，executor将最终终止，此时没有任务正在执行，没有任务正在等待执行，也没有新任务可以提交。”*/
